package ai.people.netmon.auth;

import ai.people.netmon.auth.properties.AuthProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

/**
 * @description: cms管理系统启动类
 * @author: Xing.Wei
 * @time: 2020-09-02 11:21
 */
@EnableConfigurationProperties(AuthProperties.class)
@EnableFeignClients(value = {"ai.people.core.feign.api.system"})
@ComponentScan(basePackages = {"ai.people.netmon.framework"}) // 扫描common下的所有类
@ComponentScan(basePackages = {"ai.people.netmon.auth"})
@SpringBootApplication
public class AuthenticateApplication9032 {
    public static void main(String[] args) {
        SpringApplication.run(AuthenticateApplication9032.class, args);
    }



    @Bean
    //@LoadBalanced
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        //设置restTemplate远程调用时候，对400和401不让报错，正确返回数据
        restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
            @Override
            public void handleError(ClientHttpResponse response) throws IOException {
                if (response.getRawStatusCode() != 400 && response.getRawStatusCode() != 401) {
                    super.handleError(response);
                }
            }
        });
        return restTemplate;
    }
}
